<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>注册</title>
    <link rel="stylesheet" href="./css/common.css">
    <link rel="stylesheet" href="./css/login.css">
    <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
</head>
<body>
    <div class="nav">
        <div class="left">
            <img src="./asset/img/logo.png" alt="" class="via">
            <span>KOKYU博客</span>
        </div>
    </div>
    <div class="container">
        <div class="login-dialog">
            <h3>注册博客</h3>
            <div class="tips" id="tips" >提示消息</div>
            <div class="row">
                <span>用户名</span>
                <input type="text" id="username">
            </div>
            <div class="row">
                <span>密码</span>
                <input type="password" id="password">
            </div>
            <div class="row">
                <span>确认密码</span>
                <input type="password" id="rePassword">
            </div>
            <div class="jump">
                <div style="width: 50px"></div>
                <a style="font-size: 14px; width: 400px" id="href" href="./login.html">已有账号？点击登录</a>
            </div>
            <div class="row">
                <input type="submit" id="register" value="注册">
            </div>
        </div>
    </div>

    


    

    <script>
        function tips(msg) {
            const tipsBox = document.querySelector('#tips')
            tipsBox.classList.add('show')
            tipsBox.innerHTML = msg
            setTimeout(() => {
                tipsBox.classList.remove('show')
            }, 3000)
        }

        document.querySelector('#register').addEventListener('click',()=>{
            const username = document.querySelector('#username').value.trim()
            const password = document.querySelector('#password').value.trim()
            const rePassword = document.querySelector('#rePassword').value.trim()

            if (username == ''){
                tips('用户名不能为空')
                return
            }

            if (password == ''){
                tips('密码不能为空')
                return
            }

            if (rePassword == ''){
                tips('请再次输入确认密码')
                return
            }

            if(password != rePassword){
                tips('两次输入的密码不同，请再次确认密码')
                return
            }

            // console.log('111')
            axios({
                url:'http://47.98.20.202:8000/user/register/',
                method:'post',
                data:{
                    username,
                    password,
                    rePassword
                }
            }).then(res => {
                //tips('注册成功')
                window.location.href = "login.html";
            })
        })
        
        function goToLogin() {
            window.location.href = "login.html";
        }
    </script>
</body>
</html>